package com.crm.framework.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.ArrayList;
import java.util.List;

/**
 * @author luojie
 * @date 2021/1/27 22:06
 */
public class ExcelListener<T> extends AnalysisEventListener<T> {

    /**
     * 每隔5条存储数据库，实际使用中可以3000条，然后清理list ，方便内存回收
     */
    List<T> list = new ArrayList<T>();

    /**
     * 这个每一条数据解析都会来调用
     *
     * @param data
     *            one row value. Is is same as {@link AnalysisContext#()}
     * @param context
     */
    @Override
    public void invoke(T data, AnalysisContext context) {
        list.add(data);
    }
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
    }

    public List<T> get() {
        return list;
    }
    public void set(List<T> list) {
        this.list=list;
    }
}
